<template>
  <div class="register-page">
    <!-- 顶部栏 -->
    <van-nav-bar title="面经注册" ></van-nav-bar>
    <!-- 表单 -->
    <!-- 表单 -->
    <van-form @submit="onSubmit">
      <van-field   v-model="username" label="用户名"  name="username"  placeholder="用户名"
      :rules="[{ required: true, message: '请填写用户名' },
      {pattern:/^\w{5,15}$/, message: '用户名是5-15位'}]" />
      <van-field    v-model="password" label="密码"  name="password" placeholder="密码"
       :rules="[{ required: true, message: '请填写密码' },
       {pattern:/^\w{5,15}$/,message: '密码是5-15位'}]" />
      <div style="margin: 16px;"></div>
      <van-button round block type="info" native-type="submit">提交</van-button>
    </van-form>
    <!-- 跳转注册页 -->
    <a  class="link" href="#/login">跳转注册页</a>
  </div>
</template>

<script>
/*  导入user组件 */
import { userRegister } from '@/api/user.js'
export default {
  name: 'register-page',
  data () {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    async onSubmit (values) {
      console.log(values)
      const { data } = await userRegister(values)
      console.log(data)
      // (4) 点击完提交跳转登录页面
      this.$router.push('/login')
    }
  }
}
</script>

<style lang="less" scoped>
.link {
  color: #069;
  font-size: 12px;
  padding-right: 20px;
  float: right;
}
</style>
